Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Generate a continuous variable at the*firm level

    I would like to generate a continuous variable at the firm level. For the sample below, I would like to generate a new variable that illustrates the percentage of employees that are "female, older than 22, have a master degree " to employees that are "Older than 22 and have master degree" for each firm-year observation.

    companyid year employeeid Female, older than 22 and have master degree Female, older than 22 and have a master degree
    293475073 2005 10 1 1
    293475073 2005 11 0 0
    293475073 2005 5 1 1
    982726482 2005 12 0 0
    982726482 2005 11 0 0
    982726482 2005 5 1 1
    23452345234 2006 10 1 1
    23452345234 2006 6 0 0
    23452345234 2006 7.00E+00 1 0
    18938422 2006 8.00E+00 1 0
    18938422 2006 6 0 0
    18938422 2006 1.50E+01 0 0
    18938422 2006 1.60E+01 1 0
    980232133 2007 1.70E+01 1 1
    980232133 2007 1.80E+01 0 0
    3456546 2007 1.90E+01 0 0
    3456546 2007 1.70E+01 1 1

  • #2
    You have two columns that are the same, which must be a mistake. But let's suppose you have flag1=1 if "female, older than 22, Masters" and flag2 = "older than 22, masters". Then this should do it:

    . bysort companyid year : egen percent=mean(cond(flag2,flag1,.))

    hth,
    Jeph

    Comment


    • #3
      Sorry for the mistake. This is the correct table.
      companyid year employeeid Older than 22 and have a master degree (flag2) Female, older than 22 and have a master degree (flag1)
      293475073 2005 10 1 1
      293475073 2005 11 0 0
      293475073 2005 5 1 1
      982726482 2005 12 0 0
      982726482 2005 11 0 0
      982726482 2005 5 1 1
      23452345234 2006 10 1 1
      23452345234 2006 6 0 0
      23452345234 2006 7.00E+00 1 0
      18938422 2006 8.00E+00 1 0
      18938422 2006 6 0 0
      18938422 2006 1.50E+01 0 0
      18938422 2006 1.60E+01 1 0
      980232133 2007 1.70E+01 1 1
      980232133 2007 1.80E+01 0 0
      3456546 2007 1.90E+01 0 0
      3456546 2007 1.70E+01 1 1
      Is this code going to generate the sum of flag1 divided by the sum of flag2 for each firm-year observation? because that is the one I need.

      Code:
      bysort companyid year : egen percent=mean(cond(flag2,flag1,.))

      Comment

      Working...
      X